package com.util.mail;

import com.util.configuration.ConfigurationParametersManager;
import com.util.exceptions.InternalErrorException;

public class MailHelperFactory {
    private final static String CLASS_NAME_PARAMETER =
        "MailHelperFactory/className";

    private final static Class mailClass = getMailClass();
    
    private MailHelperFactory() {}
    
    private static Class getMailClass() {
    
        Class theClass = null;
    
        try {
        
            String delegateClassName = 
                ConfigurationParametersManager.getParameter(
                    CLASS_NAME_PARAMETER);
            
            theClass = Class.forName(delegateClassName);
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return theClass;
        
    }
    
    public static MailHelper getMailHelper() 
        throws InternalErrorException {
        
        try {        
            return (MailHelper) mailClass.newInstance();
        } catch (Exception e) {
            throw new InternalErrorException(e);
        }
        
    }
}
